<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <script src="../layui/layui.js" charset="utf-8"></script>
</head>

<body>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-lg-offset3" layui-col-lg6>
            <div class="layui-form layuimini-form">
                <form class="layui-form" action="" lay-filter="userForm">
                    <div class="layui-form-item">
                        <label class="layui-form-label">医生id：</label>
                        <div class="layui-input-block">
                            <input type="text" name="doctorId" required lay-verify="required" placeholder="请输入医生id"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">医生姓名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="doctorName" required lay-verify="required" disabled="disabled" placeholder="医生姓名"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">患者id：</label>
                        <div class="layui-input-block">
                            <input type="text" name="userId" required lay-verify="required" placeholder="请输入患者id"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">患者姓名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="userName" required lay-verify="required" disabled="disabled" placeholder="患者姓名"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <!-- id 隐藏 -->
                    <input type="hidden" name="id" value="" class="layui-input">



                    <div class="layui-form-item">
                        <label class="layui-form-label">患者病症：</label>
                        <div class="layui-input-block">
                            <input type="text" name="disease" required lay-verify="required" placeholder="患者病症"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">病症描述：</label>
                        <div class="layui-input-block">
                            <textarea name="description" placeholder="请输入病情" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">药品总价：</label>
                        <div class="layui-input-block">
                            <input type="text" name="totalPrice" required lay-verify="required" disabled="disabled" placeholder="药品总价"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否支付：</label>
                        <div class="layui-input-block">
                            <input type="radio" name="payStatus" value="已支付" title="已支付" >
                            <input type="radio" name="payStatus" value="未支付" title="未支付" checked>
                        </div>
                    </div>
                    <div class="layui-form-item" id="hidden">
                        <label class="layui-form-label">支付方式：</label>
                        <div class="layui-input-block">
                            <select name="payType" lay-verify="required">
                                <option value=""></option>
                                <option value="微信支付">微信支付</option>
                                <option value="支付宝支付">支付宝支付</option>
                                <option value="现金支付">现金支付</option>
                            </select>
                        </div>
                    </div>

                    


                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>



<script>

    //Demo
    layui.use('form', function () {
        // 表单对象 form
        var form = layui.form
            // jquery 对象 $
            , $ = layui.jquery;



        // var item = $('input[name=sex]:checked').val();
        // if(item === '未支付') {
        //     document.getElementById("hidden").style.visibility="hidden";
        // }

        var data = JSON.parse(localStorage.getItem("PrescriptionItem"));

        //给表单数据赋值
        form.val("userForm",{
            "id":data.id,
            "doctorId":data.doctorId,
            "doctorName":data.doctorName,
            "userId":data.userId,
            "userName":data.userName,
            "disease":data.disease,
            "description":data.description,
            "totalPrice":data.totalPrice,
            "payStatus":data.payStatus,
            "payType":data.payType,
        });


        var token = JSON.parse(localStorage.getItem("token"));

        //监听提交
        form.on('submit(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                "url":"http://localhost:8080/demo/prescription/updatePrescriptionById",
                "data": data.field,
                "success":function(result){
                    if(result.code==0){

                        // 关闭弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);

                    }else{
                        layer.msg(result.msg);
                    }
                },
                "dataType":"json"
            });

            return false;
        });
    });
</script>


</body>

</html>